import 'package:flutter/material.dart';

class TouchCallback extends StatefulWidget {
  final Widget child;
  final VoidCallback onPress;
  final bool isFeed;
  final Color backgroundColor;
  const TouchCallback({
    super.key,
    required this.child,
    required this.onPress,
    this.isFeed = true,
    this.backgroundColor = const Color(0xFFd8d8d8),
  });

  @override
  State<TouchCallback> createState() => _TouchCallbackState();
}

class _TouchCallbackState extends State<TouchCallback> {
  Color _color = Colors.transparent;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.onPress,
      onPanDown: (details) {
        if (widget.isFeed == false) return;
        setState(() {
          _color = widget.backgroundColor;
        });
      },
      onPanCancel: () {
        setState(() {
          _color = Colors.transparent;
        });
      },
      child: Container(
        color: _color,
        child: widget.child,
      ),
    );
  }
}
